﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HCFramework.API.LINQ;

namespace HCFramework.Page.User.MyAccount
{
    public partial class MyAccount : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                BindData();
            }
        }

        private void BindData()
        {
            HCFramework.API.LINQ.User u = C.UserController.GetCurrentUser();
            LiteralUsername.Text = u.Username;
            TextBoxEmail.Text = u.Email;
            TextBoxFirstName.Text = u.FirstName;
            TextBoxLastName.Text = u.LastName;
        }

        protected void ButtonUpdate_Click(object sender, EventArgs e)
        {
            HCDataContext db = new HCDataContext();
            API.LINQ.User u = C.UserController.Get(C.UserController.GetUsername(), db);
            u.Email = TextBoxEmail.Text;
            u.FirstName = TextBoxFirstName.Text;
            u.LastName = TextBoxLastName.Text;
            C.UserController.Update(u, db);

            Message1.ShowSuccess("Cập nhật thành công");
        }
    }
}